if (NOT EOSIO_WASM_OLD_BEHAVIOR STREQUAL "On")
   macro(add_contract CONTRACT_NAME TARGET)
      add_executable( ${TARGET} ${ARGN} )
      target_compile_options( ${TARGET} PUBLIC -abigen )
      get_target_property(BINOUTPUT ${TARGET} BINARY_DIR)
      target_compile_options( ${TARGET} PUBLIC -abigen_output=${BINOUTPUT}/${TARGET}.abi )
      target_compile_options( ${TARGET} PUBLIC -contract ${CONTRACT_NAME} )
      file(GLOB contracts ${CMAKE_CURRENT_SOURCE_DIR}/${CONTRACT_NAME}.contracts.md ${CMAKE_CURRENT_SOURCE_DIR}/${CONTRACT_NAME}.clauses.md)
      if(contracts)
         set_source_files_properties(${ARGN} PROPERTIES OBJECT_DEPENDS ${contracts})
      endif()
   endmacro()
   macro (target_ricardian_directory TARGET DIR)
      target_compile_options( ${TARGET} PUBLIC -R${DIR} )
      file(GLOB contracts ${DIR}/*.contracts.md ${DIR}/*.clauses.md)
      get_target_property(contract_sources ${TARGET} SOURCES)
      if(contracts)
         set_source_files_properties(${contract_sources} PROPERTIES OBJECT_DEPENDS ${contracts})
      endif()
   endmacro()

else()
   macro(add_contract CONTRACT_NAME TARGET)
      add_executable( ${TARGET}.wasm ${ARGN} )
      target_compile_options( ${TARGET}.wasm PUBLIC -abigen )
      get_target_property(BINOUTPUT ${TARGET}.wasm BINARY_DIR)
      target_compile_options( ${TARGET}.wasm PUBLIC -abigen_output=${BINOUTPUT}/${TARGET}.abi )
      target_compile_options( ${TARGET}.wasm PUBLIC -contract ${CONTRACT_NAME} )
      file(GLOB contracts ${CMAKE_CURRENT_SOURCE_DIR}/${CONTRACT_NAME}.contracts.md ${CMAKE_CURRENT_SOURCE_DIR}/${CONTRACT_NAME}.clauses.md)
      if(contracts)
         set_source_files_properties(${ARGN} PROPERTIES OBJECT_DEPENDS ${contracts})
      endif()
   endmacro()
   macro (target_ricardian_directory TARGET DIR)
      target_compile_options( ${TARGET}.wasm PUBLIC -R${DIR} )
      file(GLOB contracts ${DIR}/*.contracts.md ${DIR}/*.clauses.md)
      get_target_property(contract_sources ${TARGET}.wasm SOURCES)
      if(contracts)
         set_source_files_properties(${contract_sources} PROPERTIES OBJECT_DEPENDS ${contracts})
      endif()
   endmacro()
endif()

macro (add_native_library TARGET)
   add_library( ${TARGET} ${ARGN} )
   target_compile_options( ${TARGET} PUBLIC -fnative )
endmacro()

macro (add_native_executable TARGET)
   cmake_policy(SET CMP0002 OLD)
   add_executable( ${TARGET} ${ARGN} )
   target_compile_options( ${TARGET} PUBLIC -fnative )
   set_target_properties( ${TARGET} PROPERTIES LINK_FLAGS "-fnative" SUFFIX "" )
   get_target_property(BINOUTPUT ${TARGET} BINARY_DIR)
   if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND APPLE)
      target_compile_options( ${TARGET} PUBLIC -g )
      find_program ( name NAMES "dsymutil" )
      if ( name )
         add_custom_command( TARGET ${TARGET} POST_BUILD COMMAND dsymutil ${BINOUTPUT}/${TARGET} )
      endif()
   endif()
endmacro()

